import { MenuItem, MenuTreeItem, MenuType } from "./models";
import req, { ResponseData } from "/@/api/req";
import { buildShortUUID } from "/@/utils/uuid";

export const Api = {
  sysMenu: "sys-menu",
  sysMenuRoutes: "sys-menu/routes",

  // getMenuTreeData: "system/menu/treeselect",
  // menu: "system/menu/",
  // roleMenuTreeselect: "system/menu/roleMenuTreeselect/",
  // getRouters: "getRouters",
};

export function getMenuTreeData() {
  return req.commonGet<MenuTreeItem[]>(
    Api.sysMenuRoutes,
    {},
    {
      useGlobalLoading: false,
    }
  );
}

// export function getRoleMenu(roleId: number) {
//   return req.commonGetResponse(Api.roleMenuTreeselect + roleId, {}, { useGlobalLoading: false });
// }

export function getMenuData() {
  return req.commonGet<MenuItem[]>(
    Api.sysMenuRoutes,
    {},
    {
      useGlobalLoading: false,
    }
  );
}

function getMenuItem(name: string, path: string, subMenu?: MenuItem[]): MenuItem {
  return {
    id: buildShortUUID(),
    menuName: name,
    path,
    icon: "icon-card",
    menuType: subMenu && subMenu.length > 0 ? MenuType.FEATURE : MenuType.FUNCTION,
    orderNum: 1,
    subMenu,
  };
}

export function getStaticMenuData(): MenuItem[] {
  return [
    getMenuItem("系统管理", "sysManage", [
      getMenuItem("系统定义", "sysDef", [
        getMenuItem("菜单定义", "menuDef"),
        getMenuItem("系统参数定义", "sysParamDef"),
      ]),
      getMenuItem("字典管理", "dictManage", [
        getMenuItem("行政区域字典", "regionDict"),
        getMenuItem("商品类别字典", "productCategoryDict"),
        getMenuItem("计量单位字典", "measurementUnitDict"),
      ]),
      getMenuItem("权限管理", "permissionManage", [
        getMenuItem("操作权限组定义", "operPermissonDef"),
        getMenuItem("数据权限组定义", "dataPermissionDef"),
        getMenuItem("操作日志", "operLog"),
      ]),
      getMenuItem("组织架构管理", "orgManage", [
        getMenuItem("组织架构定义", "orgDef"),
        getMenuItem("操作员管理", "operatorManage"),
      ]),
      getMenuItem("接口管理", "apiManage", [getMenuItem("标准API", "standardApi")]),
    ]),
  ];
}
